<template>
  <q-btn @click="handleClick" :disable="isDebouncing" />
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue';
import { debounce } from 'lodash';

export default defineComponent({
  name: 'debounce-button',

  props: {
    onClick: {
      type: Function as (...args: any) => any,
      required: true,
    },
    delay: {
      type: Number,
      default: 500,
    },
  },

  setup(props) {
    const isDebouncing = ref(false);

    const handleClick = debounce(props.onClick, props.delay);
    return { isDebouncing, handleClick };
  },
});
</script>
